<?php

function spAjaxResponse()
{
	// remove colon if there is one at the end
	$dbhost = DB_HOST;
	$dbhost = rtrim( DB_HOST, ":" );
	
	R::setup( "mysql:host=".$dbhost.";dbname=".DB_NAME, DB_USER, DB_PASSWORD );
	R::debug( false ) ;
	R::exec( "SET SESSION sql_mode=''" );

	$_REQUEST = unMagicQuotify($_REQUEST);

	$formType = isset( $_REQUEST["formType"] )?$_REQUEST["formType"]:"";
	$callback = isset($_REQUEST["callback"])? $_REQUEST["callback"]:"";
	
	if ( $callback!="" )
	{
		call_user_func_array( $callback, array() );
		die();
	}
	
	if ( isset($_REQUEST["loadonly"]) )
	{
		$loadonly = $_REQUEST["loadonly"];
		call_user_func_array( $loadonly, array() );
		die();
	}
	
	// this is deprecated use callback instead
	if ( $formType=="loadonly" )
	{
		$loadonly = $_REQUEST["loadonly"];
		call_user_func_array( $loadonly, array() );
	}
	else
	{
		$buttonPressed = $_REQUEST["button"];
		call_user_func_array( $buttonPressed, array() );
	}
	
	die();
}


?>